import { Component, OnDestroy, OnInit } from '@angular/core';
import { EzFormComponent } from '../ez-form';
import { EzFormControlComponent } from '../ez-form-control';
import { EzFormGroupComponent } from '../ez-form-group';
import { EzFormItemComponent } from '../ez-form-item';
import { EzDatepicker } from './ez-datepicker';
import { EzDatepickerConfiguration } from './ez-datepicker.configuration';

@Component({
  selector: 'ez-datepicker',
  templateUrl: './ez-datepicker.component.html',
  styleUrls: ['./ez-datepicker.component.less'],
  providers: [{ provide: EzFormControlComponent, useExisting: EzDatepickerComponent }],
})
export class EzDatepickerComponent extends EzFormControlComponent<EzDatepickerConfiguration, Date>
  implements EzDatepicker, OnInit, OnDestroy {
  constructor(
    protected ezForm: EzFormComponent,
    protected ezFormGroup: EzFormGroupComponent,
    protected ezFormItem: EzFormItemComponent
  ) {
    super(ezForm, ezFormGroup, ezFormItem);
  }

  ngOnInit(): void {
    super.ngOnInit();
  }

  ngOnDestroy(): void {
    super.ngOnDestroy();
  }

  checkConfiguration(configuration: EzDatepickerConfiguration): void {}

  defaultDisabledDate: (date: Date) => boolean = date => {
    if (this.ezFormControlConfiguration.disabledDate) {
      return this.ezFormControlConfiguration.disabledDate(date, this, this.ezFormGroup, this.ezForm);
    }
    return false;
  };

  defaultDisabledTime: (
    current: Date
  ) => {
    nzDisabledHours(): number[];
    nzDisabledMinutes(hour: number): number[];
    nzDisabledSeconds(hour: number, minute: number): number[];
  } = current => {
    return {
      nzDisabledHours: this.ezFormControlConfiguration.disabledTime
        ? this.ezFormControlConfiguration.disabledTime(current, this, this.ezFormGroup, this.ezForm).nzDisabledHours
        : () => [],
      nzDisabledMinutes: this.ezFormControlConfiguration.disabledTime
        ? this.ezFormControlConfiguration.disabledTime(current, this, this.ezFormGroup, this.ezForm).nzDisabledMinutes
        : () => [],
      nzDisabledSeconds: this.ezFormControlConfiguration.disabledTime
        ? this.ezFormControlConfiguration.disabledTime(current, this, this.ezFormGroup, this.ezForm).nzDisabledSeconds
        : () => [],
    };
  };
}
